// pages/categorylist/categorylist.js
import config from "../../utils/config.js"
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    vip: "https://kiefaluo.gitee.io/beautifulgirl/images/shengji.png",
    goodsList:[],
    choos:'',
    choosID:'',
    goods:[]
  },
  toproDetail:function(e){
    console.log(e.currentTarget.dataset.id)
      wx.navigateTo({
        url: '../proDetail/proDetail?id=' + this.data.goodsList[e.currentTarget.dataset.index].id,
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      choos:wx.getStorageSync('id'),
      choosID:wx.getStorageSync('caID')
    })
    var cateID = wx.getStorageSync('caID');
    if (that.data.choos == "newGoodsList"){
      wx.request({
        url: config.index,
        success: function (res) {
          that.setData({
            goodsList: res.data.data.newGoodsList
          })
        }
      })
    }
    if (that.data.choos == "hotGoodsList"){
      wx.request({
        url: config.index,
        success: function (res) {
          that.setData({
            goodsList: res.data.data.hotGoodsList
          })
        }
      })
    }
    if (that.data.choosID != "" && that.data.choos == ""){
      wx.request({
        url: config.category,
        data:{
          categoryId: cateID
        },
        success:function(res){
            console.log(res);
          that.setData({
            goodsList:res.data.data.data
          })
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})